<?php

namespace App\Http\Controllers;

use App\Common\ApiResponse;
use App\Common\ResponseCode;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Http\JsonResponse;
use Illuminate\Routing\Controller as BaseController;
use Validator;

class ApiController extends BaseController
{

    use AuthorizesRequests, DispatchesJobs, ValidatesRequests, ApiResponse;

    // 控制器名
    public $functionName = "";
    //方法名
    public $methodName = "";
    //Redis
    public $redis = "";

    public function __construct()
    {
        $str = explode('@', request()->route()->getActionName());
        $this->functionName = substr($str[0], 0, strpos($str[0], 'Controller'));
        $this->methodName = $str[1];
    }


    /**
     * 接口响应
     * @param int $code
     * @param string $message
     * @param array $data
     * @return JsonResponse
     */
    protected function _response($data = [], $code = ResponseCode::SUCCESS, $message = '请求成功')
    {
        return $this->apiResponse($data, $code, $message);
    }
}
